using JT808Protocol.Models.BodyParserStrategy.Others;
using JT808Protocol.Models.Enums;
using System;
using System.Collections.Generic;

namespace JT808Protocol.Models.BodyParserStrategy
{
    /// <summary>
    /// 外设状态信息
    /// </summary>
    public class ItemPeripheralStatus : IJT808Body
    {
        public ItemPassthroughPeripheralBase ItemPassthroughPeripheralBase { get; set; }

        /// <summary>
        /// 0x01：正常工作
        /// 0x02：待机状态
        /// 0x03：升级维护
        /// 0x04：设备异常
        /// 0x10：断开连接
        /// </summary>
        public byte WorkStatus { get; set; }

        /// <summary>
        /// 按位设置：0表示无，1表示有
        /// bit0：摄像头异常
        /// bit1：主存储器异常
        /// bit2：辅存储器异常
        /// bit3：红外补光异常
        /// bit4：扬声器异常
        /// bit5：电池异常
        /// bit6 ~bit9：预留
        /// bit10：通讯模块异常
        /// bit11：定位模块异常
        /// bit12 ~bit31：预留
        /// </summary>
        public uint AlarmStatus;

        public override IJT808Body ReadBody(ReadOnlySpan<byte> source, ref int startIndex)
        {
            ItemPassthroughPeripheralBase = new ItemPassthroughPeripheralBase();

            var idByte = source[startIndex];
            if (Enum.IsDefined(typeof(EnumPeripheralType), idByte))
            {
                ItemPassthroughPeripheralBase.AdditionId = (EnumPeripheralType)idByte;
            }
            else
            {
                ItemPassthroughPeripheralBase.AdditionId = EnumPeripheralType.Undefine;
            }

            ItemPassthroughPeripheralBase.DataLength = (byte)(source[startIndex] + 1);

            WorkStatus = source[startIndex + 2];
            AlarmStatus = source[startIndex + 3];

            return this;
        }

        public override List<byte> WriteToBytes()
        {
            throw new NotImplementedException();
        }
    }
}